Reorder received_events by id asc

The implementation of latest_events() assumed that while it wasn't
actually the case; the association of received_events has a default
scope of `order(id: :desc)`.

Akinori MUSHA 7 years ago
parent
commit
63c7ec5fdd
1 changed files with 3 additions and 2 deletions
  1. 3 2
      app/models/agents/data_output_agent.rb

+ 3 - 2
app/models/agents/data_output_agent.rb

@@ -190,6 +190,8 @@ module Agents
190 190
     end
191 191
 
192 192
     def latest_events(reload = false)
193
+      received_events = received_events().reorder(id: :asc)
194
+
193 195
       events =
194 196
         if (event_ids = memory[:event_ids]) &&
195 197
            memory[:events_order] == events_order &&
@@ -207,8 +209,7 @@ module Agents
207 209
 
208 210
         new_events =
209 211
           if last_event_id = memory[:last_event_id]
210
-            received_events.where(Event.arel_table[:id].gt(last_event_id)).
211
-              order(id: :asc).to_a
212
+            received_events.where(Event.arel_table[:id].gt(last_event_id)).to_a
212 213
           else
213 214
             source_ids.flat_map { |source_id|
214 215
               # dig twice as many events as the number of